package com.TCP_UDP网络编程.homeWork;

import java.io.IOException;
import java.net.*;

public class UDP01_client {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(9998);

        byte[] bytes = "四大名著".getBytes();
        DatagramPacket packet = new DatagramPacket(bytes, bytes.length, InetAddress.getLocalHost(), 9999);
        socket.send(packet);

        bytes = new byte[1024];
        packet = new DatagramPacket(bytes, bytes.length);
        socket.receive(packet);

        byte[] data = packet.getData();
        int length = packet.getLength();
        System.out.println(new String(data,0,length));
    }
}
